home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 55 / MOBICLIC 55.ISO / DATA / ARRIBA / SWF_ARRIBA / arri01.swf / scripts / DefineSprite_76 / frame_1 / DoAction.as
Text File  |  2003-06-02  |  5KB  |  233 lines

  1. function pause(pPause)
  2. {
  3.    if(pPause)
  4.    {
  5.       gotoAndStop(4);
  6.    }
  7.    else
  8.    {
  9.       gotoAndStop(9);
  10.    }
  11. }
  12. function init(pSide)
  13. {
  14.    if(pSide == null)
  15.    {
  16.       pSide = 0;
  17.    }
  18.    _side = pSide;
  19.    mcGraph.mcSide.gotoAndStop(_side + 1);
  20.    mcGraph.mcSide._rotation = - _rotation;
  21.    vGameMC = _parent.mcGame;
  22.    vGameMC.registerPlayer(this,_side);
  23.    mcControl.gotoAndStop("Void");
  24.    if(vGameMC.vControlTab[_side] == null)
  25.    {
  26.       this.getHighLight(true);
  27.       if(_side == _parent._startSide)
  28.       {
  29.          hasBall(1);
  30.          vGameMC._targetMC = this;
  31.       }
  32.       else
  33.       {
  34.          hasBall(0);
  35.       }
  36.    }
  37.    if(0 < pSide)
  38.    {
  39.       call("MouseBot");
  40.       var lFactor = _parent._factor;
  41.    }
  42.    else
  43.    {
  44.       call("Mouse");
  45.       var lFactor = 1;
  46.    }
  47.    vSpeed = lFactor * _parent.uSpeed;
  48.    vSpeedwBall = lFactor * _parent.uSpeedwBall;
  49.    _X = _X + _parent.uPlacement * (Math.random() * 2 - 1);
  50.    _Y = _Y + _parent.uPlacement * (Math.random() * 2 - 1);
  51.    vXMin = _parent.mcBounds._x;
  52.    vYMin = _parent.mcBounds._y;
  53.    vXMax = _parent.mcBounds._x + _parent.mcBounds._width;
  54.    vYMax = _parent.mcBounds._y + _parent.mcBounds._height;
  55.    checkBounds();
  56.    _radius = 20 * _xscale / 100;
  57.    vDeg2Rad = 0.017453292519943295;
  58.    vCos = Math.cos(_rotation * vDeg2Rad);
  59.    vSin = Math.sin(_rotation * vDeg2Rad);
  60.    vLaunchDist = 24;
  61.    vLaunchSpeed = _parent.uShoot;
  62.    vDropSpeed = _parent.uDrop;
  63. }
  64. function getHighLight(pControl)
  65. {
  66.    var lOld;
  67.    if(pControl)
  68.    {
  69.       lOld = vGameMC.vControlTab[this._side];
  70.       lOld._control = 0;
  71.       lOld.mcControl.gotoAndStop("Void");
  72.       vGameMC.vControlTab[_side] = this;
  73.       _control = 1;
  74.       this.mcControl.gotoAndPlay("Control");
  75.    }
  76.    else
  77.    {
  78.       lOld = vGameMC.vLightTab[this._side];
  79.       if(!lOld._control)
  80.       {
  81.          lOld.mcControl.gotoAndStop("Void");
  82.       }
  83.       vGameMC.vLightTab[_side] = this;
  84.       if(!_control)
  85.       {
  86.          mcControl.gotoAndStop("Light");
  87.       }
  88.    }
  89. }
  90. function checkBounds()
  91. {
  92.    if(_X < vXMin)
  93.    {
  94.       _X = vXMin;
  95.    }
  96.    else if(vXmax < _X)
  97.    {
  98.       _X = vXMax;
  99.    }
  100.    if(_Y < vYMin)
  101.    {
  102.       _Y = vYMin;
  103.    }
  104.    else if(vYmax < _Y)
  105.    {
  106.       _Y = vYMax;
  107.    }
  108. }
  109. function hasBall(pHasBall)
  110. {
  111.    _hasBall = pHasBall;
  112.    if(pHasBall)
  113.    {
  114.       mcGraph.gotoAndStop("Ball");
  115.    }
  116.    else
  117.    {
  118.       mcGraph.gotoAndStop(1);
  119.    }
  120. }
  121. function loop()
  122. {
  123.    if(_stun)
  124.    {
  125.       _stun--;
  126.       if(_stun == 0)
  127.       {
  128.          mcGraph.mcEyes.gotoAndStop(1);
  129.       }
  130.    }
  131.    if(_control)
  132.    {
  133.       mcGraph.mcSide._rotation = - _rotation;
  134.       if(_hasBall)
  135.       {
  136.          mcGraph.mcBall._rotation = - _rotation;
  137.          if(0 < _shield)
  138.          {
  139.             _shield--;
  140.          }
  141.       }
  142.       getLoop();
  143.       getGoal();
  144.       var lX = vGoalX - _X;
  145.       var lY = vGoalY - _Y;
  146.       var lDist2 = lX * lX + lY * lY;
  147.       if(1 < lDist2)
  148.       {
  149.          var lAngle = Math.atan2(lY,lX);
  150.          _rotation = lAngle / vDeg2Rad;
  151.          vCos = Math.cos(lAngle);
  152.          vSin = Math.sin(lAngle);
  153.       }
  154.       if(lDist2 >= _radius * _radius)
  155.       {
  156.          if(_hasBall)
  157.          {
  158.             _speedX = vSpeedwBall * vCos;
  159.             _speedY = vSpeedwBall * vSin;
  160.          }
  161.          else
  162.          {
  163.             _speedX = vSpeed * vCos;
  164.             _speedY = vSpeed * vSin;
  165.          }
  166.          _X = _X + _speedX;
  167.          _Y = _Y + _speedY;
  168.          checkBounds();
  169.       }
  170.       var lColMC = vGameMC.getCollidingPlayer(this,null,true);
  171.       var lTargetPlayer = vGameMC.getNearestPlayer(vGoalX,vGoalY,this._side);
  172.       var lShoot = getShoot();
  173.       if(lShoot)
  174.       {
  175.          if(_hasBall and !_stun)
  176.          {
  177.             var lX = _X + vCos * vLaunchDist;
  178.             var lY = _Y + vSin * vLaunchDist;
  179.             var lSpeedX = vCos * vLaunchSpeed;
  180.             var lSpeedY = vSin * vLaunchSpeed;
  181.             vGameMC.launchBall(lX,lY,lSpeedX,lSpeedY);
  182.             hasBall(false);
  183.          }
  184.          if(lTargetPlayer != null)
  185.          {
  186.             lTargetPlayer.getHighLight(true);
  187.          }
  188.       }
  189.       else if(lTargetPlayer != this)
  190.       {
  191.          lTargetPlayer.getHighLight(false);
  192.       }
  193.       mcGraph.mcSide._rotation = - _rotation;
  194.       if(_hasBall)
  195.       {
  196.          mcGraph.mcBall._rotation = - _rotation;
  197.       }
  198.    }
  199. }
  200. function dropBall(pMC)
  201. {
  202.    if(0 < pMC._stun)
  203.    {
  204.       return null;
  205.    }
  206.    getStun();
  207.    var lX = _X - pMC._x;
  208.    var lY = _Y - pMC._y;
  209.    var lNorm = - Math.sqrt(lX * lX + lY * lY);
  210.    lX /= lNorm;
  211.    lY /= lNorm;
  212.    var lSpeedX = lX * vDropSpeed;
  213.    var lSpeedY = lY * vDropSpeed;
  214.    lX = _X + lX * vLaunchDist;
  215.    lY = _Y + lY * vLaunchDist;
  216.    vGameMC.launchBall(lX,lY,lSpeedX,lSpeedY);
  217.    hasBall(false);
  218. }
  219. function getStun()
  220. {
  221.    _stun = _parent.uStun;
  222.    mcGraph.mcEyes.gotoAndStop(2);
  223. }
  224. if(_name.substr(0,1) == "r")
  225. {
  226.    init(1);
  227. }
  228. else
  229. {
  230.    init(0);
  231. }
  232. pause(true);
  233.